package com.hb.trade.server.project.section.service.item;

import cn.hutool.core.collection.CollUtil;
import com.hb.core.pojo.enums.CommonTypeEnum;
import com.hb.core.pojo.enums.NoticeNatureEnum;
import com.hb.core.pojo.project.notice.entity.Notice;
import com.hb.core.pojo.project.section.dto.BidSectionDTO;
import com.hb.trade.server.project.notice.service.NoticeService;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.hb.core.pojo.enums.ButtonStatusEnum.DONE;
import static com.hb.core.pojo.enums.ButtonStatusEnum.NONE;


/**
 * 招标/采购
 * 按钮权限方法
 * 所有按钮权限的判断不涉及以下判断
 * fzzn.trade.service.itemlogic包下的所有service类均不涉及
 * (即遇到任意以下因素时判断为显示, 这些已经在数据库字段中进行了维护)
 * 1. 项目类型(招标方式, 询比价, 竞争性谈判, 磋商等)
 * 2. 当前登录用户的企业角色
 *
 * @author gaoyf/update by zhaojk
 * @since 2021-9-15
 */
@Service
public class BidService extends CommonService {

    private final NoticeService noticeService;

    public BidService(NoticeService noticeService) {
        this.noticeService = noticeService;
    }

    /**
     * 公告查看
     *
     * @param section 标段对象
     * @return int
     * @author zhaojk
     * @date 2022/3/7 18:02
     */
    public int noticeView(BidSectionDTO section) {
        return equals(section, CommonTypeEnum.OPEN);
    }

    /**
     * 邀请书查看
     *
     * @author zhaojk
     * @date 2021-9-15
     */
    public int inviteView(BidSectionDTO section) {
        return equals(section, CommonTypeEnum.INVITE);
    }

    /**
     * 控制价管理
     *
     * @author zhaojk
     * @date 2021-9-15
     */
    public int controlPrice(BidSectionDTO section) {
        List<Notice> notices = noticeService.findNoticeBySectionId(section.getId(), NoticeNatureEnum.LIMIT.getCode());
        if (CollUtil.isEmpty(notices)) {
            return NONE.getCode();
        }
        return DONE.getCode();
    }

    /**
     * 招标/采购文件查看
     *
     * @author zhaojk
     * @date 2021-9-15
     */
    public int bidFileView(BidSectionDTO section) {
        return DONE.getCode();
    }

    /**
     * 招标/采购文件澄清
     *
     * @author zhaojk
     * @date 2021-9-15
     */
    public int bidFileClarify(BidSectionDTO section) {
        return DONE.getCode();
    }
}
